import UserStore from '@/stores/business';
import { showConfirmDialog, showToast } from 'vant';

const success = (message, onClose = () => { }, duration = 1500) => {
    showToast({
        type: 'success',
        message,
        duration,
        onClose,
    })
}

const fail = (message, onClose = () => { }, duration = 1500) => {
    showToast({
        type: 'fail',
        message,
        duration,
        onClose,
    })
}

//普通的，没有成功和失败的图标
const toast = (message, onClose = () => { }, duration = 1500) => {
    showToast({
        type: 'text',
        message,
        duration,
        onClose
    })
}

export default {
    install(app) {
        //实例化
        const UserInit = UserStore();

        // 从状态管理提取business属性，保持响应式
        const { business } = storeToRefs(UserInit);

        // 定义全局属性
        app.config.globalProperties.$success = success;
        app.config.globalProperties.$fail = fail;
        app.config.globalProperties.$toast = toast;
        app.config.globalProperties.$confirm = showConfirmDialog;

        app.config.globalProperties.$business = business;
    }
}
